package com.example.demo.entry;

import org.springframework.ldap.core.AttributesMapper;

import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;

/**
 * @author: YZD
 * @Date: 2020-04-29 22:11
 */
public class PersonAttributesMapper implements AttributesMapper<Person> {

    @Override
    public Person mapFromAttributes(Attributes attributes) throws NamingException {
        Person user = new Person();
        Attribute userPassword = attributes.get("userPassword");
        if (userPassword != null) {
            user.setUserPassword(attributes.get("userPassword").toString());
        }
        Attribute uid = attributes.get("uid");
        if (uid != null) {
            user.setUid(uid.get().toString());
        }
        Attribute cn = attributes.get("cn");
        if (cn != null) {
            user.setCn(cn.get().toString());
        }
        Attribute sn = attributes.get("sn");
        if (sn != null) {
            user.setSn(sn.get().toString());
        }
        Attribute mail = attributes.get("mail");
        if (mail != null) {
            user.setMail(mail.get().toString());
        }
        Attribute telephoneNumber = attributes.get("telephoneNumber");
        if (telephoneNumber != null) {
            user.setTelephoneNumber(telephoneNumber.get().toString());
        }
        Attribute description = attributes.get("description");
        if (description != null) {
            user.setDescription(description.get().toString());
        }
        Attribute seeAlso = attributes.get("seeAlso");
        if (seeAlso != null) {
            user.setSeeAlso(seeAlso.get().toString());
        }
        Attribute givenName = attributes.get("givenName");
        if (givenName != null) {
            user.setGivenName(givenName.get().toString());
        }
        Attribute initials = attributes.get("initials");
        if (initials != null) {
            user.setInitials(givenName.get().toString());
        }
        Attribute displayName = attributes.get("displayName");
        if (displayName != null) {
            user.setDisplayName(displayName.get().toString());
        }
        Attribute physicalDeliveryOfficeName = attributes.get("physicalDeliveryOfficeName");
        if (physicalDeliveryOfficeName != null) {
            user.setPhysicalDeliveryOfficeName(physicalDeliveryOfficeName.get().toString());
        }
        Attribute o = attributes.get("o");
        if (o != null) {
            user.setO(o.get().toString());
        }
        Attribute title = attributes.get("title");
        if (physicalDeliveryOfficeName != null) {
            user.setTitle(title.get().toString());
        }
        Attribute departmentNumber = attributes.get("departmentNumber");
        if (departmentNumber != null) {
            user.setDepartmentNumber(departmentNumber.get().toString());
        }
        Attribute ou = attributes.get("ou");
        if (ou != null) {
            user.setOu(ou.get().toString());
        }
        Attribute homePhone = attributes.get("homePhone");
        if (homePhone != null) {
            user.setHomePhone(homePhone.get().toString());
        }
        Attribute pager = attributes.get("pager");
        if (pager != null) {
            user.setPager(pager.get().toString());
        }
        Attribute mobile = attributes.get("mobile");
        if (mobile != null) {
            user.setMobile(mobile.get().toString());
        }
        Attribute facsimileTelephoneNumber = attributes.get("facsimileTelephoneNumber");
        if (facsimileTelephoneNumber != null) {
            user.setFacsimileTelephoneNumber(facsimileTelephoneNumber.get().toString());
        }
        Attribute homePostalAddress = attributes.get("homePostalAddress");
        if (homePostalAddress != null) {
            user.setHomePostalAddress(homePostalAddress.get().toString());
        }
        Attribute roomNumber = attributes.get("roomNumber");
        if (roomNumber != null) {
            user.setRoomNumber(roomNumber.get().toString());
        }
        Attribute street = attributes.get("street");
        if (street != null) {
            user.setStreet(street.get().toString());
        }
        Attribute postOfficeBox = attributes.get("postOfficeBox");
        if (postOfficeBox != null) {
            user.setPostOfficeBox(postOfficeBox.get().toString());
        }
        Attribute postalAddress = attributes.get("postalAddress");
        if (facsimileTelephoneNumber != null) {
            user.setPostalAddress(postalAddress.get().toString());
        }
        Attribute l = attributes.get("l");
        if (l != null) {
            user.setL(l.get().toString());
        }
        Attribute st = attributes.get("st");
        if (st != null) {
            user.setSt(st.get().toString());
        }
        Attribute postalCode = attributes.get("postalCode");
        if (postalCode != null) {
            user.setPostalCode(postalCode.get().toString());
        }
        Attribute employeeNumber = attributes.get("employeeNumber");
        if (employeeNumber != null) {
            user.setEmployeeNumber(employeeNumber.get().toString());
        }
        Attribute employeeType = attributes.get("employeeType");
        if (employeeType != null) {
            user.setEmployeeType(employeeType.get().toString());
        }
        Attribute businessCategory = attributes.get("businessCategory");
        if (businessCategory != null) {
            user.setBusinessCategory(businessCategory.get().toString());
        }
        Attribute carLicense = attributes.get("carLicense");
        if (carLicense != null) {
            user.setCarLicense(carLicense.get().toString());
        }
        return user;
    }
}
